package com.ny.zmb.openapi.util;

import com.alibaba.fastjson.JSONObject;
import com.ny.zmb.openapi.controller.entity.Result;
import com.ny.zmb.openapi.ysutil.YsHttpUtil;
import com.ny.zmb.openapi.ysutil.base.EYinShengBase;
import com.ny.zmb.openapi.ysutil.common.ServiceEnum;
import com.ny.zmb.openapi.ysutil.common.YsPayConstant;
import com.ny.zmb.openapi.ysutil.publicInterface.QueryAmountReqCommand;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.UUID;

@Service
public class YsMerChantUtil extends EYinShengBase {

    @Resource
    private YsHttpUtil ysHttpUtil;

    /**
     * 商户绑定银行卡查询
     * @param command
     * @return
     */
    public JSONObject bankAccountQuery(QueryAmountReqCommand command){
        if (null == command){
            throw new RuntimeException("参数不能为空");
        }
        command.setRequestNo(getUUID());
        try {
            JSONObject send = ysHttpUtil.send(ServiceEnum.Bank_Account_Query, YsPayConstant.ENV_PRD,
                    MERCHANT_PRX, MERCHANT_PRX_PWD,ServiceEnum.Bank_Account_Query.getApiName(), command);
            JSONObject result = send.getJSONObject("bizResponseJson");
            String subCode = result.getString("subCode");
            if (!"COM000".equals(subCode)){
                throw new RuntimeException(result.getString("subMsg"));
            }
            return result;
        }catch (Exception var){
            throw new RuntimeException(var.getMessage());
        }
    }

    private static String getUUID(){
        String uuid = UUID.randomUUID().toString().replaceAll("-","");
        return uuid;
    }
}
